<?php
/*
	插件概览
	分销插件主要显示哪些数据？
		1、基本数据
		分销订单总数 会员总数 团长总数 
		分销订单近七天增长趋势折线图 会员数近七天增长折线图 团长近七天增长折线图 
		收益总笔数/金额 结算总笔数/金额
		饼状图显示各状态收益数额  饼状图显示各状态结算总笔数/金额
		
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'welcome';
$tabs=array(
	array('op'=>'welcome','title'=>'概况'),
	array('op'=>'line','title'=>'趋势'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='welcome'){
	//会员
	$member=array(
		'member'=>$this->count('member',array('uniacid'=>$_SESSION['uniacid'])),
		'agent'=>$this->count('team',array('uniacid'=>$_SESSION['uniacid'])),
		'stop'=>$this->count('member',array('uniacid'=>$_SESSION['uniacid'],'stop'=>1)),
	);
	$return['htmls'][]=array('type'=>'data','one_num'=>4,'title'=>'会员概况','datas'=>array(
		array('title'=>'会员数量','num'=>1,'data'=>$member['member']),
		array('title'=>'团长数量','num'=>1,'data'=>$member['agent']),
		array('title'=>'黑名单','num'=>1,'data'=>$member['stop']),
	));
	//收益
	$month_start=strtotime(date('Ym').'01');
	$commission_month['num']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'createtime >'=>$month_start));
	$commission_month['money']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'type'=>2,'createtime >'=>$month_start),'jifen');
	$commission['num']=$this->count('commission',array('uniacid'=>$_SESSION['uniacid'],'type'=>2));
	$commission['money']=$this->sum('commission',array('uniacid'=>$_SESSION['uniacid'],'type'=>2),'jifen');
	//结算
	$balance_month['num']=$this->count('balance',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start));
	$balance_month['money']=$this->sum('balance',array('uniacid'=>$_SESSION['uniacid'],'createtime >'=>$month_start),'money');
	$balance['num']=$this->count('balance',array('uniacid'=>$_SESSION['uniacid']));
	$balance['money']=$this->sum('balance',array('uniacid'=>$_SESSION['uniacid']),'money');
	$return['htmls'][]=array('type'=>'data','one_num'=>3,'title'=>'收益概况','datas'=>array(
		array('title'=>'收益笔数/金额','num'=>2,'data'=>array($commission['num'],$commission['money'])),
		array('title'=>'结算笔数/金额','num'=>2,'data'=>array($balance['num'],$balance['money'])),
		array('title'=>'本月收益笔数/金额','num'=>2,'data'=>array($commission_month['num'],$commission_month['money'])),
		array('title'=>'本月结算笔数/金额','num'=>2,'data'=>array($balance_month['num'],$balance_month['money'])),
	));
	
	$commission_pie=array(
		'title'=>'收益概况',
		'tablename'=>$this->tablename('commission'),
		'width'=>'50%',
		'field'=>'status',
		'field_options'=>$this->commission_status,
		'params'=>array('uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($commission_pie);
	$balance_pie=array(
		'title'=>'结算订单概况',
		'tablename'=>$this->tablename('balance'),
		'width'=>'50%',
		'field'=>'status',
		'field_options'=>$this->balance_status,
		'params'=>array('uniacid'=>$_SESSION['uniacid']),
	);
	$return['htmls'][]=model('core/echart')->pie($balance_pie);
	set_html('title','分销概况');
	exi($return);
}
if($_RQ['op']=='line'){
	//趋势
	$order_params=array(
		'title'=>'近30天分销订单走势',
		'data'=>array(
			'tablename'=>$this->tablename('agent_order'),
		),
	);
	$return['htmls'][]=model('core/echart')->line($order_params);
	$member_params=array(
		'title'=>'近三十天会员/团长增长走势',
		'data'=>array(
			'会员增长'=>array(
				'tablename'=>$this->tablename('member'),
			),
			'团长增长'=>array(
				'tablename'=>$this->tablename('member'),
				'params'=>array('uniacid'=>$_SESSION['uniacid'],'is_agent'=>1),
				'time_field'=>'agenttime',
			)
		),
	);
	$return['htmls'][]=model('core/echart')->line($member_params);
	set_html('title','分销趋势');
	exi($return);
}
if($_RQ['op']=='basic'){
	//系统运行参数
	$item=array();
	$item['level']=$this->level_types[$this->setting['level']];
	$item['commission']="顾客在商城下单并付款后开始给上线计算收益，按照订单实际支付金额【{$this->commission_types[$this->setting['commissiontype']]}】乘以相应团长收益比例得到收益数额。";
	$item['balance']="收益所属订单完成后【{$this->setting['balance_day']}】天成为可结算状态，可结算收益达【{$this->setting['balance_money']}元】可申请结算，审核通过的结算单由管理员进行打款操作，打款手续费为待打款收益的【{$this->setting['balance_per']}%】。";
	$return['item']=$item;
	$return['htmls'][]=array(
		'type'=>'look',
		'desc'=>'系统基础运行参数',
		'look'=>array(
			array('type'=>'string','name'=>'level','title'=>'分销层级'),
			array('type'=>'string','name'=>'commission','title'=>'收益规则'),
			array('type'=>'string','name'=>'balance','title'=>'结算规则'),
		),
	);
	exi($return);
}